//
//  TableViewCell.m
//  UEAssistant
//
//  Created by mac on 2017/4/19.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "TableViewCell.h"
#import "ZZCircleProgress.h"

@interface TableViewCell (){

    NSInteger              _cir_width;
}

@property (nonatomic, strong) UILabel             *fileName;

@property (nonatomic, strong) ZZCircleProgress    *circleTrans;
@property (nonatomic, strong) ZZCircleProgress    *circleEdit;
@property (nonatomic, strong) ZZCircleProgress    *circlePro;

@property (nonatomic, strong) UIImageView         *headViewTrans;
@property (nonatomic, strong) UIImageView         *headViewEdit;
@property (nonatomic, strong) UIImageView         *headViewPro;

@property (nonatomic, strong) UILabel             *nameTrans;
@property (nonatomic, strong) UILabel             *nameEdit;
@property (nonatomic, strong) UILabel             *namePro;

@property (nonatomic, strong) UIButton            *ButtonTrans;
@property (nonatomic, strong) UIButton            *ButtonEdit;
@property (nonatomic, strong) UIButton            *ButtonPro;

@property (nonatomic, strong) UILabel             *wordCountTrans;
@property (nonatomic, strong) UILabel             *wordCountEdit;
@property (nonatomic, strong) UILabel             *wordCountPro;

@property (nonatomic, strong) UILabel             *timeTrans;
@property (nonatomic, strong) UILabel             *timeEdit;
@property (nonatomic, strong) UILabel             *timePro;

@end

@implementation TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setLayouout];
    }
    return self;
}

- (void)setLayouout{
        
    _fileName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 30*Radio)];
    _fileName.backgroundColor = RGB(247, 247, 247, 1);
    _fileName.textColor = RGB(72, 79, 87, 1);
    _fileName.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _fileName.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_fileName];

    
    _headViewTrans = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40*Radio, 40*Radio)];
    _headViewTrans.center = CGPointMake(60*Radio, 60*Radio+_fileName.center.y);
    _headViewTrans.layer.cornerRadius = 20*Radio;
    _headViewTrans.layer.masksToBounds = YES;
    _headViewTrans.image = [UIImage imageNamed:@"user"];
    _headViewTrans.layer.shouldRasterize = YES; //圆角缓存
    _headViewTrans.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [self addSubview:_headViewTrans];
    
    _headViewEdit = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40*Radio, 40*Radio)];
    _headViewEdit.center = CGPointMake(Screen_Width/2, 60*Radio+_fileName.center.y);
    _headViewEdit.layer.cornerRadius = 20*Radio;
    _headViewEdit.layer.masksToBounds = YES;
    _headViewEdit.image = [UIImage imageNamed:@"user"];
    _headViewEdit.layer.shouldRasterize = YES; //圆角缓存
    _headViewEdit.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [self addSubview:_headViewEdit];
    
    _headViewPro = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40*Radio, 40*Radio)];
    _headViewPro.center = CGPointMake(Screen_Width-60*Radio, 60*Radio+_fileName.center.y);
    _headViewPro.layer.cornerRadius = 20*Radio;
    _headViewPro.layer.masksToBounds = YES;
    _headViewPro.image = [UIImage imageNamed:@"user"];
    _headViewPro.layer.shouldRasterize = YES; //圆角缓存
    _headViewPro.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [self addSubview:_headViewPro];
    
    _nameTrans = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _nameTrans.center = CGPointMake(_headViewTrans.center.x, _headViewTrans.center.y+_headViewTrans.frame.size.height+10*Radio);
    _nameTrans.backgroundColor = [UIColor whiteColor];
    _nameTrans.textColor = RGB(51, 51, 51, 1);
    _nameTrans.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _nameTrans.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_nameTrans];
    
    _nameEdit = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _nameEdit.center = CGPointMake(_headViewEdit.center.x, _headViewEdit.center.y+_headViewEdit.frame.size.height+10*Radio);
    _nameEdit.backgroundColor = [UIColor whiteColor];
    _nameEdit.textColor = RGB(51, 51, 51, 1);
    _nameEdit.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _nameEdit.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_nameEdit];

    _namePro = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _namePro.center = CGPointMake(_headViewPro.center.x, _headViewPro.center.y+_headViewPro.frame.size.height+10*Radio);
    _namePro.backgroundColor = [UIColor whiteColor];
    _namePro.textColor = RGB(51, 51, 51, 1);
    _namePro.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _namePro.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_namePro];

    _wordCountTrans = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*Radio, 20*Radio)];
    _wordCountTrans.center = CGPointMake(_nameTrans.center.x, _nameTrans.center.y+_nameTrans.frame.size.height+50*Radio);
    _wordCountTrans.backgroundColor = [UIColor whiteColor];
    _wordCountTrans.textColor = RGB(181, 190, 198, 1);
    _wordCountTrans.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _wordCountTrans.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_wordCountTrans];

    _wordCountEdit = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*Radio, 20*Radio)];
    _wordCountEdit.center = CGPointMake(_nameEdit.center.x, _nameEdit.center.y+_nameEdit.frame.size.height+50*Radio);
    _wordCountEdit.backgroundColor = [UIColor whiteColor];
    _wordCountEdit.textColor = RGB(181, 190, 198, 1);
    _wordCountEdit.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _wordCountEdit.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_wordCountEdit];

    _wordCountPro = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*Radio, 20*Radio)];
    _wordCountPro.center = CGPointMake(_namePro.center.x, _namePro.center.y+_namePro.frame.size.height+50*Radio);
    _wordCountPro.backgroundColor = [UIColor whiteColor];
    _wordCountPro.textColor = RGB(181, 190, 198, 1);
    _wordCountPro.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _wordCountPro.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_wordCountPro];

    _timeTrans = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _timeTrans.center = CGPointMake(_wordCountTrans.center.x, _wordCountTrans.center.y+_wordCountTrans.frame.size.height);
    _timeTrans.backgroundColor = [UIColor whiteColor];
    _timeTrans.textColor = RGB(181, 190, 198, 1);
    _timeTrans.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _timeTrans.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_timeTrans];
    
    _timeEdit = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _timeEdit.center = CGPointMake(_wordCountEdit.center.x, _wordCountEdit.center.y+_wordCountEdit.frame.size.height);
    _timeEdit.backgroundColor = [UIColor whiteColor];
    _timeEdit.textColor = RGB(181, 190, 198, 1);
    _timeEdit.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _timeEdit.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_timeEdit];
    
    _timePro = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*Radio, 20*Radio)];
    _timePro.center = CGPointMake(_wordCountPro.center.x, _wordCountPro.center.y+_wordCountPro.frame.size.height);
    _timePro.backgroundColor = [UIColor whiteColor];
    _timePro.textColor = RGB(181, 190, 198, 1);
    _timePro.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _timePro.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_timePro];
}

- (void)setProgressTrans:(CGFloat)trans edit:(CGFloat)edit pro:(CGFloat)pro{

    if (Screen_Width == 320) {
        _cir_width = 143;
    }else if(Screen_Width == 375){
        _cir_width = 150;
    }else{
        _cir_width = 155;
    }
    
    if (trans > 0) {
        _circleTrans = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(0, 0, _cir_width, _cir_width) pathBackColor:nil pathFillColor:RGB(15, 192, 247,1) startAngle:90*3 strokeWidth:2];
        _circleTrans.progress = trans;
        _circleTrans.showProgressText = YES;
        _circleTrans.center = _headViewTrans.center;
        _circleTrans.animationModel = CircleIncreaseSameTime;
        [self addSubview:_circleTrans];
    }
    
    if (edit > 0) {
        _circleEdit = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(0, 0, _cir_width, _cir_width) pathBackColor:nil pathFillColor:RGB(15, 192, 247,1) startAngle:90*3 strokeWidth:2];
        _circleEdit.progress = edit;
        _circleEdit.showProgressText = YES;
        _circleEdit.center = _headViewEdit.center;
        _circleEdit.animationModel = CircleIncreaseSameTime;
        [self addSubview:_circleEdit];
    }
    
    if (pro > 0) {
        _circlePro = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(0, 0, _cir_width, _cir_width) pathBackColor:nil pathFillColor:RGB(15, 192, 247,1) startAngle:90*3 strokeWidth:2];
        _circlePro.progress = pro;
        _circlePro.showProgressText = YES;
        _circlePro.center = _headViewPro.center;
        _circlePro.animationModel = CircleIncreaseSameTime;
        [self addSubview:_circlePro];
    }

    _ButtonTrans = [UIButton buttonWithType:UIButtonTypeSystem];
    _ButtonTrans.frame = CGRectMake(0, 0, 76*Radio, 30*Radio);
    _ButtonTrans.center = CGPointMake(_nameTrans.center.x, _nameTrans.center.y+35*Radio);
    _ButtonTrans.backgroundColor = [UIColor whiteColor];
    _ButtonTrans.layer.borderWidth = 1.f;
    _ButtonTrans.layer.borderColor = RGB(155, 210, 249, 1).CGColor;
    [_ButtonTrans setTitleColor:RGB(37, 197, 248, 1) forState:UIControlStateNormal];
    _ButtonTrans.layer.cornerRadius = 5;
    [_ButtonTrans setTitle:@"指派翻译" forState:UIControlStateNormal];
    [_ButtonTrans addTarget:self action:@selector(assignTransRequest:) forControlEvents:UIControlEventTouchUpInside];
    _ButtonTrans.tag = 100;
    _ButtonTrans.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    [self addSubview:_ButtonTrans];
    
    _ButtonEdit = [UIButton buttonWithType:UIButtonTypeSystem];
    _ButtonEdit.frame = CGRectMake(0, 0, 76*Radio, 30*Radio);
    _ButtonEdit.center = CGPointMake(_nameEdit.center.x, _nameEdit.center.y+35*Radio);
    _ButtonEdit.backgroundColor = [UIColor whiteColor];
    _ButtonEdit.layer.borderWidth = 1.f;
    _ButtonEdit.layer.borderColor = RGB(155, 210, 249, 1).CGColor;
    [_ButtonEdit setTitleColor:RGB(37, 197, 248, 1) forState:UIControlStateNormal];
    _ButtonEdit.layer.cornerRadius = 5;
    [_ButtonEdit setTitle:@"指派编辑" forState:UIControlStateNormal];
    [_ButtonEdit addTarget:self action:@selector(assignEditRequest:) forControlEvents:UIControlEventTouchUpInside];
    _ButtonEdit.tag = 200;
    _ButtonEdit.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    [self addSubview:_ButtonEdit];
    
    _ButtonPro = [UIButton buttonWithType:UIButtonTypeSystem];
    _ButtonPro.frame = CGRectMake(0, 0, 76*Radio, 30*Radio);
    _ButtonPro.center = CGPointMake(_namePro.center.x, _namePro.center.y+35*Radio);
    _ButtonPro.backgroundColor = [UIColor whiteColor];
    _ButtonPro.layer.borderWidth = 1.f;
    _ButtonPro.layer.borderColor = RGB(155, 210, 249, 1).CGColor;
    [_ButtonPro setTitleColor:RGB(37, 197, 248, 1) forState:UIControlStateNormal];
    _ButtonPro.layer.cornerRadius = 5;
    [_ButtonPro setTitle:@"指派校对" forState:UIControlStateNormal];
    [_ButtonPro addTarget:self action:@selector(assignProRequest:) forControlEvents:UIControlEventTouchUpInside];
    _ButtonPro.tag = 300;
    _ButtonPro.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    [self addSubview:_ButtonPro];
}


#pragma mark -- Events

- (void)assignTransRequest:(UIButton *)sender{

    if (self.delegate && [self.delegate respondsToSelector:@selector(AssignTaskButton:andUserId:)]) {
        [self.delegate AssignTaskButton:sender andUserId:1];
    }

}

- (void)assignEditRequest:(UIButton *)sender{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(AssignTaskButton:andUserId:)]) {
        [self.delegate AssignTaskButton:sender andUserId:2];
    }

    
}
- (void)assignProRequest:(UIButton *)sender{
   
    if (self.delegate && [self.delegate respondsToSelector:@selector(AssignTaskButton:andUserId:)]) {
        [self.delegate AssignTaskButton:sender andUserId:3];
    }

}


- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
